import type { Router } from 'vue-router'
import { useUserStoreWithOut } from '@/stores/modules/user'
import { App } from '@/utils/app'

/**
 * 权限访问守卫配置
 * @param router
 */
const setupAccessGuard = (router: Router) => {
  router.beforeEach(async (_to, _from) => {
    const userStore = useUserStoreWithOut()
    const token = userStore.getToken()
    // 存在token进行自动登录
    if (token) {
      // await App.getInstance().handleAuth()
      return true
    } else {
      return true
    }
  })
}

/**
 * 项目守卫配置
 * @param router
 */
const createRouterGuard = (router: Router) => {
  /** 权限访问 */
  setupAccessGuard(router)
}

export { createRouterGuard }
